package com.burger.counter.servlets;

import java.io.IOException;
import java.util.Hashtable;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.burger.counter.beans.Region;
import com.burger.counter.beans.SignatureBurgerBowl;
import com.burger.counter.beans.SignatureBurgerBun;
import com.burger.counter.business.SignatureBurgerBowlBusiness;
import com.burger.counter.business.SignatureBurgerBunBusiness;

/**
 * Servlet implementation class SignatureBurgerServlet
 */
public class SignatureBurgerServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SignatureBurgerServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("I am in Signature Servlet");
		SignatureBurgerBowl signatureBurgerList[] =null;
		SignatureBurgerBun signatureBurgerBunList[]=null;
		//SignatureBurgerBowl signatureBurgerList;
		SignatureBurgerBowlBusiness signatureBI=new SignatureBurgerBowlBusiness();
		SignatureBurgerBunBusiness signatureBunBI=new SignatureBurgerBunBusiness();
		
		HttpSession session = request.getSession(true);
		int RegionId=(Integer) session.getAttribute("RegionId");
		System.out.println("Session region id is :" + RegionId);
		try {
			signatureBurgerList = signatureBI.getSignatureBurgerBowlDetails(RegionId);
			signatureBurgerBunList=signatureBunBI.getSignatureBurgerBunDetails(RegionId);
			//signatureBurgerList.setSigBurgerBowlId(0);
			//signatureBurgerList.setSigBurgerBowlName("Hello");
		} 
		catch (Exception e) {
			e.printStackTrace();
		}
		for(int i=0;i<signatureBurgerBunList.length;i++)
		{
			System.out.println("Servlet " + signatureBurgerBunList[i].getSigBurgerBunName());
		}
		session.setAttribute("signatureBurgerData", signatureBurgerList);
		session.setAttribute("signatureBurgerBunData", signatureBurgerBunList);
		/*
		System.out.println("region size" +signatureBurgerList);		
		Hashtable<Integer,String> regionDetails = new Hashtable<Integer,String>();
		for(int i =0 ;i<signatureBurgerList.length;i++)
		{
			regionDetails.put(signatureBurgerList[i].getRegionId(), signatureBurgerList[i].getRegionName());
			System.out.println(signatureBurgerList[i].getRegionId() + "" + signatureBurgerList[i].getRegionName() );
		}
		*/
		//request.getSession().setAttribute("regionData", regionDetails);
		
		
		RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/SignatureBurgerPage.jsp");
		dispatcher.forward(request, response);
	}

}
